package com.datang.pet.api.messageController;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-06-20 10:42
 * @notify
 * @version 1.0
 */

import com.datang.pet.common.response.Result;
import com.datang.pet.common.utils.MD5;
import com.datang.pet.common.utils.StringUtils;
import com.datang.pet.service.CommentService;
import com.datang.pet.vo.AddTwoCommentRequest;
import com.datang.pet.vo.ReplayCommentRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ReplayCommentController {
    @Autowired
    private CommentService commentService;

    @PostMapping("/replayComment")
    private Result replayComment(@RequestBody ReplayCommentRequest replayCommentRequest)throws Exception {

        //一层评论id
        String modelId = replayCommentRequest.getModelId();


        //喵文id
        String talkId = replayCommentRequest.getTalkId();

        //发送人
        String userId = replayCommentRequest.getUserId();
        //接收人
        String replay = replayCommentRequest.getReplay();

        //一层评论内容或二层评论内容
        String ohterContent = replayCommentRequest.getOhterContent();

        //内容
        String content = replayCommentRequest.getContent();


        try {
            userId = (MD5.decryptData(userId));
        } catch (Exception e) {
            throw new Exception("userId解密出错！");
        }

        AddTwoCommentRequest addTwoCommentRequest = new AddTwoCommentRequest();
        addTwoCommentRequest.setId(StringUtils.getId());
        addTwoCommentRequest.setOneCommentId(modelId);
        addTwoCommentRequest.setCommentContent(content);
        addTwoCommentRequest.setTwoCommentUserId(userId);
        addTwoCommentRequest.setReplyUserId(replay);
        addTwoCommentRequest.setTalkId(talkId);
        addTwoCommentRequest.setOhterContent(ohterContent);
        commentService.addTwoComment(addTwoCommentRequest);
        return Result.ok("");
    }
}
